const app = getApp();
const https = require('../../utils/https');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type: 'ALL',
    commentTab: [
      {id: 'ALL','name':'全部'},
      {id: 'PICS','name':'有图'},
      {id: 'GOODS','name':'好评'},
      {id: 'MIDDLE','name':'中评'},
      {id: 'LAST','name':'差评'},
    ],
    commentList: [],
    goods_id: 0,
    page: 0
  },
  tabTap(e){
    this.setData({
      type: e.currentTarget.dataset.type,
      page: 0,
      commentList: [],
    })
    this.getList();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.goods_id && options.goods_id > 0) {
      this.setData({
        goods_id: options.goods_id
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getList();
  },
  /**
   * @xk 获取评价列表
   * @param {*} res 
   */
  getList: function(res){
    var that = this,
        type = this.data.type,
        commentList= this.data.commentList,
        page = this.data.page,
        goods_id = this.data.goods_id;
    https.post('getCommonList',{type:type,goods_id:goods_id,page:page},true,'加载中').then(res=>{
      if(res.list){
        commentList.push.apply(commentList,res.list);
      }
      that.setData({
        commentList: commentList,
        page: res.page
      })
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    that.setData({
      type: 'ALL',
      page: 0,
      commentList: []
    })
    this.onShow();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getList();
  },

})